package pt.iscte.dcti.es.rhplus.sistema;

import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * @author Gustavo Cabral
 * @author Helena Monteiro
 * @author Joao Catarino
 * @author Tiago Moreiras
 */
public class UtensiliosParaStrings {
	public static boolean eUmNumero(final String string) {
		boolean e_um_numero = true;

		for (char character : string.toCharArray()) {
			if (!Character.isDigit(character))
				return false;
		}

		return e_um_numero;
	}

	public static boolean eUmEmail(final String string) {
		String email_regex = "^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$";
		Pattern pattern = Pattern.compile(email_regex);

		Matcher matcher = pattern.matcher(string);

		return matcher.matches();
	}

	public static boolean eUmNumeroReal(final String string) {
		String email_regex = "^\\d+\\.?\\d+?$";
		Pattern pattern = Pattern.compile(email_regex);

		Matcher matcher = pattern.matcher(string);

		return matcher.matches();
	}

	public static LinkedList<String> separaTipoEnumerado(final String tipo_enumerado) {
		LinkedList<String> especialidades = new LinkedList<String>();
		String regex = "(?!')\\w*(?=')";
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(tipo_enumerado);
		while (matcher.find()) {
			int start = matcher.start();
			int end = matcher.end();
			especialidades.add(tipo_enumerado.substring(start, end));
		}

		return especialidades;
	}

//Dani5{
    public static boolean eApenasLetras(final String string) {

            for (char character : string.toCharArray()) {
                if (!Character.isLetter(character) && !Character.isWhitespace(character))
                    return true;
            }

            return false;
        }
//}Dani5

//Dani8{
    public static boolean eLoginValido(final String login){

        for(char c: login.toCharArray()){
            if(!Character.isLetter(c) && !Character.isWhitespace(c) && !Character.isDigit(c))
                return false;
        }

        return true;
    }

//}Dani8

}
